package gui.funcionarios;

import ge.usuarios.Diretor;
import ge.usuarios.Funcionario;
import ge.usuarios.Professor;
import gui.GerenciadorDeJanelas;
import gui.MenuCadastra;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.BorderFactory;

import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.LayoutStyle;
import javax.swing.border.BevelBorder;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SelecionaFuncionario.java
 *
 * Created on 14/11/2010, 17:38:36
 */


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 *
 * @author Caio
 */
public class SelecionaFuncionario extends javax.swing.JPanel {
    public static Funcionario funcionario;
    public static Professor professor;
    public static AlteraFuncionario alteraFuncionario;
    private JLabel jLabel2;
    private JLabel jLabel1;
    public static AlteraProfessor alteraProfessor;
    public static AlteraDiretor alteraDiretor;
    
    /** Creates new form SelecionaFuncionario */
    public SelecionaFuncionario() {
        initComponents();
        
	        String saida = "";
	        try{
	        	saida += GerenciadorDeJanelas.diretor.toString();
	        }catch(Exception e){
	        	
	        }
	    	for(int i = 0; i < GerenciadorDeJanelas.todosFuncionarios.size(); i++ ){
	    		saida += GerenciadorDeJanelas.todosFuncionarios.get(i).toString();
	    	}
	        for(int j = 0; j < GerenciadorDeJanelas.todosProfessores.size(); j++){
	    		saida += GerenciadorDeJanelas.todosProfessores.get(j).toString();
	    	}
	        
	    	textArea1.setText(saida);
        
        	
        }
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        textArea1 = new java.awt.TextArea();
        campoMatricula = new java.awt.TextField();
        campoMatricula.addKeyListener(new KeyAdapter() {
        	
        });
        GroupLayout layout = new GroupLayout((JComponent)this);
        this.setLayout(layout);
        label1 = new java.awt.Label();
        ok = new javax.swing.JButton();
        bVoltar = new javax.swing.JButton();

        textArea1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        textArea1.setEditable(false);

        label1.setText("Digite a matricula do funcionario:");
        label1.setForeground(new java.awt.Color(0,102,102));
        label1.setFont(new java.awt.Font("Arial",0,12));

        ok.setText("OK");
        ok.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        ok.setBackground(new java.awt.Color(255,255,255));
        ok.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                okMouseClicked(evt);
            }
        });

        bVoltar.setText("Voltar");
        bVoltar.setBackground(new java.awt.Color(255,255,255));
        bVoltar.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        {
        	jLabel2 = new JLabel();
        	jLabel2.setText("Seleciona Funcionario");
        	jLabel2.setFont(new java.awt.Font("Arial",0,36));
        	jLabel2.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
        	jLabel2.setForeground(new java.awt.Color(0,102,102));
        }
        {
        	jLabel1 = new JLabel();
        	jLabel1.setText("Funcionarios cadastrados na Escola:");
        	jLabel1.setForeground(new java.awt.Color(0,102,102));
        	jLabel1.setFont(new java.awt.Font("Arial",0,12));
        }
        layout.setVerticalGroup(layout.createSequentialGroup()
        	.addContainerGap(27, 27)
        	.addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE)
        	.addGap(30)
        	.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	.addGap(16)
        	.addGroup(layout.createParallelGroup()
        	    .addComponent(textArea1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 331, GroupLayout.PREFERRED_SIZE)
        	    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	        .addGap(78)
        	        .addComponent(label1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addComponent(campoMatricula, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
        	        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        	        .addComponent(ok, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
        	        .addGap(179)))
        	.addGap(0, 76, Short.MAX_VALUE)
        	.addComponent(bVoltar, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
        	.addContainerGap(27, 27));
        layout.setHorizontalGroup(layout.createSequentialGroup()
        	.addContainerGap(60, 60)
        	.addGroup(layout.createParallelGroup()
        	    .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	        .addComponent(textArea1, GroupLayout.PREFERRED_SIZE, 333, GroupLayout.PREFERRED_SIZE)
        	        .addGap(120)
        	        .addGroup(layout.createParallelGroup()
        	            .addComponent(label1, GroupLayout.Alignment.LEADING, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        	            .addComponent(campoMatricula, GroupLayout.Alignment.LEADING, 0, 180, Short.MAX_VALUE)))
        	    .addGroup(layout.createSequentialGroup()
        	        .addGap(68)
        	        .addGroup(layout.createParallelGroup()
        	            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 224, GroupLayout.PREFERRED_SIZE)
        	                .addGap(213))
        	            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                .addGap(75)
        	                .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 362, GroupLayout.PREFERRED_SIZE)))
        	        .addGap(19)
        	        .addGroup(layout.createParallelGroup()
        	            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                .addComponent(ok, GroupLayout.PREFERRED_SIZE, 49, GroupLayout.PREFERRED_SIZE)
        	                .addGap(0, 57, Short.MAX_VALUE))
        	            .addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
        	                .addGap(8)
        	                .addComponent(bVoltar, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE)
        	                .addGap(0, 0, Short.MAX_VALUE)))))
        	.addContainerGap(103, 103));
        bVoltar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bVoltarMouseClicked(evt);
            }
        });

        this.setBackground(new java.awt.Color(204,204,255));
    }// </editor-fold>

    private void okMouseClicked(java.awt.event.MouseEvent evt) {
    	int matricula = 0;
    	try{
    		matricula = Integer.parseInt(campoMatricula.getText().trim());
    	}catch(Exception e){
    		JOptionPane.showMessageDialog(null, "Digite uma matricula");
    		return;
    	}
        
        for(int j = 0; j < GerenciadorDeJanelas.todosFuncionarios.size(); j++){
            if(matricula ==  GerenciadorDeJanelas.todosFuncionarios.get(j).getMatricula()){
                
                funcionario = GerenciadorDeJanelas.todosFuncionarios.get(j);
                alteraFuncionario = new AlteraFuncionario();
                GerenciadorDeJanelas.window.setContentPane(alteraFuncionario);
                GerenciadorDeJanelas.window.setVisible(true);
                return;
            }
        }
        for(int l = 0 ;l < GerenciadorDeJanelas.todosProfessores.size(); l++ ){
            if(matricula == GerenciadorDeJanelas.todosProfessores.get(l).getMatricula()){               
                professor = GerenciadorDeJanelas.todosProfessores.get(l);
                alteraProfessor = new AlteraProfessor();
                GerenciadorDeJanelas.window.setContentPane(alteraProfessor);
                GerenciadorDeJanelas.window.setVisible(true);
                return;
            }
        }
        try{
        if(matricula == GerenciadorDeJanelas.diretor.getMatricula()){
        	alteraDiretor = new AlteraDiretor();
        	GerenciadorDeJanelas.window.setContentPane(alteraDiretor);
        	GerenciadorDeJanelas.window.setVisible(true);
        	return;
        }
        }catch(Exception e){
        	
        }
        JOptionPane.showMessageDialog(null, "Matricula nao encontrada");
        return;
    }                                     

    private void bVoltarMouseClicked(java.awt.event.MouseEvent evt) {
        GerenciadorDeJanelas.window.setContentPane(GerenciadorDeJanelas.menuAltera);
        GerenciadorDeJanelas.window.setVisible(true);
    }


    // Variables declaration - do not modify
    private javax.swing.JButton bVoltar;
    private java.awt.TextField campoMatricula;
    private java.awt.Label label1;
    private javax.swing.JButton ok;
    private java.awt.TextArea textArea1;
    // End of variables declaration

}
